<?php

function get_where(){
    $where = array();
 
    $where_str = "";
    if(!empty($where)){
        $where_str = " && ".implode(" && ",$where);
    }
    return $where_str;
}

/**
 * 获取登录日志
 * @param $param
 */
//http://http://log.bajian.wan.sogou.com/?a=get_game_login_log&server_id=1&begin_time=1990-01-01
function get_[template]_log($param){

    $where_str = get_where();
    //登录时间，角色id，角色等级，平台id，区服id，战力，登录ip,
    $cmd = <<<EOT
cat {$param['log_path']}/[template]_*.txt |awk -F" " '{if($9>=%s && $9<=%s %s){print [field]}else{}}'
EOT;
    $cmd = sprintf($cmd,$param['begin_time'],$param['end_time'],$where_str);
    $data = exec_cmd($cmd,$param);
//    var_dump($res,$data);
    $log = array();
    foreach($data['data'] as $k=>$v){
        //1495075246 1124 4 21001 s1 10970 192.168.77.8
        //登录时间，角色id，角色等级，平台id，区服id，战力，登录ip,
        $login_log_arr = explode(" ",$v);
        $log[] = [templdate_log];
    }
    ajax_return($data['total'],$data['per_page'],$data['total_page'],$data['page'],$log);
}